package com.resou.reader.search.adpter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.resou.reader.R;
import com.resou.reader.view.FlowLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HotAndHistoryAdapter extends RecyclerView.Adapter {

    private List<Object> mObjects;

    public HotAndHistoryAdapter() {
        mObjects.add(null);
        mObjects.add(null);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        if (viewType == 0) {
            return new TitleHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.simple_text_layout, viewGroup, false));
        } else if (viewType == 1) {
            return new FlowLayoutHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.search_hot_layout, viewGroup, false));
        } else if (viewType == 2) {
            return new TitleHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.simple_text_layout, viewGroup, false));
        } else {
            return new HistoryItemHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.search_history_item, viewGroup, false));
        }
    }

    public void setFlowLayoutData() {

    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        if (position == 0) {
            if (viewHolder instanceof TitleHolder) {
                TitleHolder titleHolder = (TitleHolder) viewHolder;
            }
        }
        if (position == 1) {
            if (viewHolder instanceof FlowLayoutHolder) {
                FlowLayoutHolder flowHolder = (FlowLayoutHolder) viewHolder;
            }
        }
        if (position == 2) {
            if (viewHolder instanceof TitleHolder) {
                TitleHolder titleHolder = (TitleHolder) viewHolder;

            }
        }
    }

    @Override
    public int getItemCount() {
        return mObjects.size();
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return 0;
        }
        if (position == 1) {
            return 1;
        }
        if (position == 2) {
            return 2;
        } else {
            return 3;
        }
    }

    class HistoryItemHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.history_item_text)
        TextView historyItemText;
        @BindView(R.id.history_item_group)
        FrameLayout historyItemGroup;

        HistoryItemHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class TitleHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.simple_text)
        TextView simpleText;
        @BindView(R.id.right_text)
        TextView rightText;

        public TitleHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class FlowLayoutHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.search_hot_group)
        FlowLayout searchHotGroup;

        public FlowLayoutHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
